package vip.zhenzicheng.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author zhenzicheng
 * @DESCRIPTION: rabbitmq工具类，抽取公用方法
 * @DATE: 2022/04/24 2:47 PM
 */
public class RabbitUtils {
  private static final ConnectionFactory connectionFactory = new ConnectionFactory();

  static {
    connectionFactory.setHost("127.0.0.1");
    connectionFactory.setPort(5672);
    connectionFactory.setUsername("zzc");
    connectionFactory.setPassword("123456");
    connectionFactory.setVirtualHost("zzc_vm");
  }

  public static Connection getConnection() {
    Connection conn = null;
    try {
      conn = connectionFactory.newConnection();
    } catch (IOException | TimeoutException e) {
      e.printStackTrace();
    }
    return conn;
  }
}
